﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace 自定义泛型集合2
{
    internal class Program
    {
        static void Main(string[] args)
        {
            Persons persons = new Persons();

            Person p = new Person() { Name = "yejing", Age = 34 };
            persons.Add(p);

            foreach (var item in persons)
            {
                Console.WriteLine((item as Person).Name);
            }

            Console.ReadKey();
        }
    }

    public class Person
    {
        protected int age;
        public int Age { get { return age; } set { age = value; } }
        protected string name;
        public string Name { get { return name; } set { name = value; } }

        public Person()
        {

        }
    }

    public class Persons : IEnumerable
    {
        List<Person> list = new List<Person>();
        public IEnumerator GetEnumerator() => list.GetEnumerator();

        public void Add(Person p) => list.Add(p);
    }
}
